#ifndef __KACHE_H__
#define __KACHE_H__
/// Includes cuda
#include <cutil_inline.h>

//TODO 4. If I try to grab all the memory available, it'll fail
#define ratioOfDramForCache 0.95f

class Cache {
protected:
	enum cacheStatus{NEVER=0, EVICTED, INCACHE};
	class lruEntry {
	public:
		lruEntry* prev;
		lruEntry* next;
		int index;
	};

	class dicEntry {
	public:
		int status;
		int offset;
		lruEntry *lruEntryPtr;
	};
public:
	virtual void init() = 0;
	virtual void printStatistics() = 0;
	dicEntry* dictionary;
	lruEntry* lruHead;
	float *devCache;
	int cachePitchInFloat;
protected:
	lruEntry *pool;
	int cacheSizeInRow;
	int occupancy;
	int hits;
	int compulsoryMisses;
	int capacityMisses;
};

class Cache_C : public Cache {
public:
	void init();
	void printStatistics();
	void evaluateCacheSize(int nPoints);
	void cleanCache();
	void findData(int index, int& cacheIndex, bool& compute);
};

//class Cache_G : public Cache {
//public:
//	__device__
//		void printStatistics() {
//			int accesses = hits + compulsoryMisses + capacityMisses;
//			printf("%d accesses, %d hits, %d compulsory misses, %d capacity misses\n", accesses, hits, compulsoryMisses, capacityMisses);
//		}
//	__device__
//		void *operator new(size_t size, void* p) {return p;}
//	__device__
//		void *operator new(size_t size) {
//			return malloc(size);
//		}
//};


#endif
